package 笔试.便利蜂;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author:谢君臣
 * @Date:2021/9/29-16:56
 * @version:1.0
 * @function: 1,00:00-05:00;1,09:00-13:00;1,09:00-13:00;0,04:00-10:00
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] split = scanner.nextLine().split(";");
        List<String> res = new ArrayList<>();
        List<String> work = new ArrayList<>();
        List<String> unwork = new ArrayList<>();

        for (String s : split) {
            String[] time = s.split(",");
            if (time[0].equals("1")) work.add(time[1]);
            else unwork.add(time[1]);
        }

        for (int i = 0; i < work.size(); i++) {
            String s = work.get(i);
            String[] work_time = s.split("-");
            for (int j = 0; j < unwork.size(); j++) {
                String s1 = unwork.get(j);
                String[] unwork_time = s1.split("-");
                int s_s = work_time[0].compareTo(unwork_time[0]);
                if (s_s < 0) {
                    int e_s = work_time[1].compareTo(unwork_time[0]);
                    if (e_s <= 0) {
                        res.add(s);
                    } else {
                        res.add(work_time[0] + "-" + unwork_time[0]);
                    }
                    break;
                } else if (s_s == 0) { // 开始时间相同
                    int e_e = work_time[1].compareTo(unwork_time[1]);
                    if (e_e > 0) {
                        work.add(unwork_time[1] + "-" + work_time[1]);
                    }
                    break;
                } else { // 开始工作时间晚
                    int s_e = work_time[0].compareTo(unwork_time[1]);
                    if (s_e >= 0) {
                        if (j == unwork.size() - 1)
                            res.add(s);
                        else
                            continue;
                    } else {
                        work.add(unwork_time[1] + "-" + work_time[1]);
                        break;
                    }
                }
            }
        }
        StringBuilder r = new StringBuilder();
        if (res.size()==0)
            System.out.println("-");
        res.sort(String::compareTo);
        for (String re : res) {
            r.append(re + ";");
        }

        System.out.println(r.substring(0, r.length() - 1));
    }
}
